package com.zr.Inquiry.mapper;

import com.zr.Inquiry.pojo.*;
import com.zr.plant.pojo.LegalPersonVo;
import com.zr.utils.ErrorMessage;
import org.apache.ibatis.annotations.*;

import javax.validation.Valid;
import javax.validation.constraints.NotBlank;
import javax.validation.constraints.NotEmpty;
import java.util.List;

@Mapper
public interface InquiryMapper {
    //法人下拉框
    @Select("select * from supplier s  left join legalperson_supplier ls on s.partnerCode=ls.partnerCode  left JOIN   legalPerson l on l.legalPersonCode=ls.legalPersonCode where l.legalPersonId =#{legalPersonId} ")
    List<PartnerVo> queryByLegalPerson(Integer legalPersonId);
    //分页查询 数据
    List<InquiryTotalVo> queryData(InquirySelectVo inquirySelectVo);
    //分页查询条数
    int queryCount(InquirySelectVo inquirySelectVo);
    //选择备件数据
    List<SpareVo> querySparePage(SelectSpareVo selectSpareVo);
    //选择备件条数
    int querySparePageCount(SelectSpareVo selectSpareVo);
    //选择供应商数据
    List<PartnerVo> queryPartnerPage(SelectPartnerVo selectPartnerVo);
    //选择供应商条数
    int queryPartnerPageCount(SelectPartnerVo selectPartnerVo);
    //9.验证法人是否存在
    @Select("select count(legalPersonId) from legalPerson where legalPersonId=#{legalPersonId}")
    LegalPersonVo selectLegalperson(Integer legalPersonId);
    //7.验证备件是否都存在
    List<SpareVo> selectSpare(List<String> list);
    //8.验证供应商是否都存在
    List<PartnerVo> selectSupplier(List<String> list1);
    //查看 询价单
    @Select("select * from inquirytotal i left join legalperson l on i.legalpersonId=l.legalpersonId where  requestForQuotationId=#{requestForQuotationId}")
    InquiryTotalVo queryInquiryByrequestForQuotationId(String requestForQuotationId);
    //查看询价单 备件
    @Select("select * from inquirysparedetail where inquiryId=#{id}")
    List<InquirySpareVo> querySpareByrequestForQuotationId(Integer requestForQuotationId);
    @Select("select * from inquirysupplierdetail where inquiryId=#{id}")
    List<InquirySupplierVo> querySupplierByrequestForQuotationId(Integer requestForQuotationId);


    //作废
    @Update("update inquirytotal set inquiryStatus=#{inquiryStatus} where requestForQuotationId=#{requestForQuotationId}")
    void modifyState(InquiryTotalVo inquiryTotalVo);


    //审核
    @Update("UPDATE inquirytotal i SET i.inquiryStatus=#{inquiryStatus} WHERE i.requestForQuotationId=#{requestForQuotationId}")
    void updateInquiryTotalInquiryStatus(String requestForQuotationId);

    //新增验证
    List<InquirySpareSupplierVo> querySpareSupplier(List<String> codeList);

    List<InquirySupplierVo> querySupplierSpare(List<String> supplierCodeList);
    @Select("select count(legalPersonId) from legalperson where legalPersonId=#{legalPersonId}")
    int queryLegalPersonById(Integer legalPersonId);

    List<String> querySpareByCodeList(List<String> codeList);

    List<String> querySupplierBySupplierCodeList(List<String> supplierCodeList);
    //新增数据
    void addInquiryTotal(InquiryTotalVo inquiryTotal);

    int selectByRequestForQuotationId(String requestForQuotationId);

    void addInquirysparedetail(List<InquirySpareVo> inquirySpareCodeVoList);

    void addInquirysupplierdetail(List<InquirySupplierVo> inquirySupplierVoList);
    //修改
    @Select("select * from inquirytotal where requestForQuotationId = #{requestForQuotationId}")
    InquiryTotalVo queryByRequestForQuotationId(String requestForQuotationId);
    
    void updateInquiryTotal(InquiryTotalVo inquiryTotal);

    @Delete("delete from inquirysparedetail where  inquiryId=#{id}")
    void deleteSpareByTotalId(Integer id);

    @Delete("delete from inquirysupplierdetail where  inquiryId=#{id}")
    void deleteSupplierByTotalId(Integer id);

    void insert(List<InquirySpareVo> inquirySpareVoList);
}
